
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>添加管理员</title>
	
    <link rel="stylesheet" href="css/main.css" media="all">
	<script src="lib/layui/layui.js" charset="utf-8"></script>

    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/jquery.form.min.js"></script>

    <script src="./js/common.js"></script>

	<script>
	    layui.use(['form','layer'], function(){ });
	</script>
	
	<style type="text/css">
		.my-marginright{
			margin-right: 40px;
		}
	</style>
</head>

<body>
<div class="x-body">
    <form class="layui-form my-marginright" id="form-add" method="post" enctype="multipart/form-data">
		
        <div class="layui-form-item">
            <label for="username" class="layui-form-label"><span class="x-red">* </span>用户名</label>
            <div class="layui-input-block">
                <input type="text" id="username" name="username" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
		    <label for="password" class="layui-form-label">
		        <span class="x-red">* </span>密码
		    </label>
		    <div class="layui-input-block">
		        <input type="password" id="password" name="password" required lay-verify="pass"
		               autocomplete="off" class="layui-input" value="">
		    </div>
		</div>

        <div class="layui-form-item">
		    <label for="L_repass" class="layui-form-label">
		        <span class="x-red">* </span>确认密码
		    </label>
		    <div class="layui-input-block">
		        <input type="password" id="L_repass" name="repassword" required lay-verify="repass"
		               autocomplete="off" class="layui-input">
		    </div>
		</div>

        <div class="layui-form-item">
            <label for="headerImg" class="layui-form-label">
                <span class="x-red">* </span>头像
            </label>
			<input type="file" id="headerImg" name="header">
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input id="state" type="radio" name="statu" value="0" title="启用" checked="checked">
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                    <div>启用</div>
                </div>
                <input type="radio" name="statu" value="1" title="禁用">
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                    <div>禁用</div>
                </div>
            </div>
        </div>
		
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  onclick="add(event)" class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
	
	
</div>

    <script>

        function add(event) {

            event.preventDefault()

            let formData = new FormData();
            formData.append("username", $('#username')[0].value);
            formData.append("password", $('#password')[0].value);
            formData.append("state", $('#state')[0].checked);
            formData.append("header", $('#headerImg')[0].files[0]);

            $.ajax({
                url: baseUrl + '/admin/admins',
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                success: function (result) {
                    console.log(result)
                },
                error(e) {
                    alert(e)
                }
            })

        }


    </script>

</body>

</html>